// // DEDate.ym // DeadEndsImport // // Created by Thomas Wetmore on 2/17/2011. // Last changed on 6/27/2011. // Copyright 2011 DeadEnds Software. All rights reserved. // // This yacc/bison file defines the grammar of DeadEnds date strings. %name-prefix = "date" %{ #import #import "DEDate.h" extern int datelex (); extern void dateerror (char* message); extern NSMutableArray* datesList; %} // The union that holds semantic values. %union { NSInteger ival; id idval; } %token OR %token AND %token MONTH %token ABOUT %token COMPUTED %token INTERPRETED %token BEFORE %token AFTER %token PROBABLY %token POSSIBLY %token BETWEEN %token FROM %token TO %token ON %token INT %type dateList date singleDate dateRange year %type prefix %% dateList : date { //NSLog(@"Date: %@", $1); datesList = [[NSMutableArray arrayWithObject: $1] retain]; } | dateList OR date { [datesList addObject: $3]; [$3 release]; } | dateList AND date { [datesList addObject: $3]; [$3 release]; } ; date : singleDate | dateRange ; singleDate : prefix MONTH INT ',' year { $$ = [[DESingleDate alloc] initPrefix: $1 year: $5 month: $2 day: $3]; } | prefix INT MONTH year { $$ = [[DESingleDate alloc] initPrefix: $1 year: $4 month: $3 day: $2]; } | prefix MONTH year { $$ = [[DESingleDate alloc] initPrefix: $1 year: $3 month: $2 day: 0]; } | prefix year { $$ = [[DESingleDate alloc] initPrefix: $1 year: $2 month: 0 day: 0]; } | prefix INT '/' INT '/' year { $$ = [[DESingleDate alloc] initPrefix: $1 year: $6 month: $2 day: $4]; } ; prefix : /* empty */ { $$ = 0; } | ABOUT { $$ = DEDatePrefixAbout; } | BEFORE { $$ = DEDatePrefixBefore; } | COMPUTED { $$ = DEDatePrefixComputed; } | INTERPRETED { $$ = DEDatePrefixInterpreted; } | AFTER { $$ = DEDatePrefixAfter; } | ON OR BEFORE { $$ = DEDatePrefixOnOrBefore; } | ON OR AFTER { $$ = DEDatePrefixOnOrAfter; } | POSSIBLY { $$ = DEDatePrefixPossibly; } | PROBABLY { $$ = DEDatePrefixProbably; } ; year : INT { $$ = [[DEYear alloc] initYear: $1 double: NO]; } | INT '/' INT { $$ = [[DEYear alloc] initYear: $1 double: YES]; } ; dateRange : BETWEEN singleDate AND singleDate { $$ = [[DEDateRange alloc] initType: DEDatePrefixBetween one: $2 two: $4]; } | FROM singleDate TO singleDate { $$ = [[DEDateRange alloc] initType: DEDatePrefixFromTo one: $2 two: $4]; } ; %% // Lexer object created externally that returns tokens. //-------------------------------------------------------------------------------------------------- extern DEDateLexer* dateLexer; // This is the lexer for the DeadEnds date parser. //-------------------------------------------------------------------------------------------------- int datelex () { int tokenType = (int) [dateLexer getToken: &datelval]; //NSLog(@"tokenType: %d", tokenType); // TODO: Remove return tokenType; }