/* * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. * * This file is part of Jam - see jam.c for Copyright information. */ /* * jamgram.yy - jam grammar * * 04/13/94 (seiwald) - added shorthand L0 for null list pointer * 06/01/94 (seiwald) - new 'actions existing' does existing sources * 08/23/94 (seiwald) - Support for '+=' (append to variable) * 08/31/94 (seiwald) - Allow ?= as alias for "default =". * 09/15/94 (seiwald) - if conditionals take only single arguments, so * that 'if foo == bar' gives syntax error (use =). * 02/11/95 (seiwald) - when scanning arguments to rules, only treat * punctuation keywords as keywords. All arg lists * are terminated with punctuation keywords. * 09/11/00 (seiwald) - Support for function calls; rules return LIST *. * 01/22/01 (seiwald) - replace evaluate_if() with compile_eval() * 01/24/01 (seiwald) - 'while' statement * 03/23/01 (seiwald) - "[ on target rule ]" support * 02/27/02 (seiwald) - un-break "expr : arg in list" syntax * 03/02/02 (seiwald) - rules can be invoked via variable names * 03/12/02 (seiwald) - set YYMAXDEPTH for big, right-recursive rules * 02/28/02 (seiwald) - merge EXEC_xxx flags in with RULE_xxx * 06/21/02 (seiwald) - support for named parameters * 10/22/02 (seiwald) - working return/break/continue statements */ %token ARG STRING %left `||` `|` %left `&&` `&` %left `=` `!=` `in` %left `<` `<=` `>` `>=` %left `!` %{ #include "jam.h" #include "lists.h" #include "variable.h" #include "parse.h" #include "scan.h" #include "compile.h" #include "newstr.h" #include "rules.h" # define YYMAXDEPTH 10000 /* for OSF and other less endowed yaccs */ # define F0 (LIST *(*)(PARSE *, LOL *, int *))0 # define P0 (PARSE *)0 # define S0 (char *)0 # define pappend( l,r ) parse_make( compile_append,l,r,P0,S0,S0,0 ) # define pbreak( l,f ) parse_make( compile_break,l,P0,P0,S0,S0,f ) # define peval( c,l,r ) parse_make( compile_eval,l,r,P0,S0,S0,c ) # define pfor( s,l,r ) parse_make( compile_foreach,l,r,P0,s,S0,0 ) # define pif( l,r,t ) parse_make( compile_if,l,r,t,S0,S0,0 ) # define pincl( l ) parse_make( compile_include,l,P0,P0,S0,S0,0 ) # define plist( s ) parse_make( compile_list,P0,P0,P0,s,S0,0 ) # define plocal( l,r,t ) parse_make( compile_local,l,r,t,S0,S0,0 ) # define pnull() parse_make( compile_null,P0,P0,P0,S0,S0,0 ) # define pon( l,r ) parse_make( compile_on,l,r,P0,S0,S0,0 ) # define prule( a,p ) parse_make( compile_rule,a,p,P0,S0,S0,0 ) # define prules( l,r ) parse_make( compile_rules,l,r,P0,S0,S0,0 ) # define pset( l,r,a ) parse_make( compile_set,l,r,P0,S0,S0,a ) # define pset1( l,r,t,a ) parse_make( compile_settings,l,r,t,S0,S0,a ) # define psetc( s,l,r ) parse_make( compile_setcomp,l,r,P0,s,S0,0 ) # define psete( s,l,s1,f ) parse_make( compile_setexec,l,P0,P0,s,s1,f ) # define pswitch( l,r ) parse_make( compile_switch,l,r,P0,S0,S0,0 ) # define pwhile( l,r ) parse_make( compile_while,l,r,P0,S0,S0,0 ) # define pnode( l,r ) parse_make( F0,l,r,P0,S0,S0,0 ) # define psnode( s,l ) parse_make( F0,l,P0,P0,s,S0,0 ) %} %% run : /* empty */ /* do nothing */ | rules { parse_save( $1.parse ); } ; /* * block - zero or more rules * rules - one or more rules * rule - any one of jam's rules * right-recursive so rules execute in order. */ block : /* empty */ { $$.parse = pnull(); } | rules { $$.parse = $1.parse; } ; rules : rule { $$.parse = $1.parse; } | rule rules { $$.parse = prules( $1.parse, $2.parse ); } | `local` list `;` block { $$.parse = plocal( $2.parse, pnull(), $4.parse ); } | `local` list `=` list `;` block { $$.parse = plocal( $2.parse, $4.parse, $6.parse ); } ; rule : `{` block `}` { $$.parse = $2.parse; } | `include` list `;` { $$.parse = pincl( $2.parse ); } | arg lol `;` { $$.parse = prule( $1.parse, $2.parse ); } | arg assign list `;` { $$.parse = pset( $1.parse, $3.parse, $2.number ); } | arg `on` list assign list `;` { $$.parse = pset1( $1.parse, $3.parse, $5.parse, $4.number ); } | `break` list `;` { $$.parse = pbreak( $2.parse, JMP_BREAK ); } | `continue` list `;` { $$.parse = pbreak( $2.parse, JMP_CONTINUE ); } | `return` list `;` { $$.parse = pbreak( $2.parse, JMP_RETURN ); } | `for` ARG `in` list `{` block `}` { $$.parse = pfor( $2.string, $4.parse, $6.parse ); } | `switch` list `{` cases `}` { $$.parse = pswitch( $2.parse, $4.parse ); } | `if` expr `{` block `}` { $$.parse = pif( $2.parse, $4.parse, pnull() ); } | `if` expr `{` block `}` `else` rule { $$.parse = pif( $2.parse, $4.parse, $7.parse ); } | `while` expr `{` block `}` { $$.parse = pwhile( $2.parse, $4.parse ); } | `rule` ARG params `{` block `}` { $$.parse = psetc( $2.string, $3.parse, $5.parse ); } | `on` arg rule { $$.parse = pon( $2.parse, $3.parse ); } | `actions` eflags ARG bindlist `{` { yymode( SCAN_STRING ); } STRING { yymode( SCAN_NORMAL ); } `}` { $$.parse = psete( $3.string,$4.parse,$7.string,$2.number ); } ; /* * assign - = or += */ assign : `=` { $$.number = VAR_SET; } | `+=` { $$.number = VAR_APPEND; } | `?=` { $$.number = VAR_DEFAULT; } | `default` `=` { $$.number = VAR_DEFAULT; } ; /* * expr - an expression for if */ expr : arg { $$.parse = peval( EXPR_EXISTS, $1.parse, pnull() ); } | expr `=` expr { $$.parse = peval( EXPR_EQUALS, $1.parse, $3.parse ); } | expr `!=` expr { $$.parse = peval( EXPR_NOTEQ, $1.parse, $3.parse ); } | expr `<` expr { $$.parse = peval( EXPR_LESS, $1.parse, $3.parse ); } | expr `<=` expr { $$.parse = peval( EXPR_LESSEQ, $1.parse, $3.parse ); } | expr `>` expr { $$.parse = peval( EXPR_MORE, $1.parse, $3.parse ); } | expr `>=` expr { $$.parse = peval( EXPR_MOREEQ, $1.parse, $3.parse ); } | expr `&` expr { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); } | expr `&&` expr { $$.parse = peval( EXPR_AND, $1.parse, $3.parse ); } | expr `|` expr { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); } | expr `||` expr { $$.parse = peval( EXPR_OR, $1.parse, $3.parse ); } | arg `in` list { $$.parse = peval( EXPR_IN, $1.parse, $3.parse ); } | `!` expr { $$.parse = peval( EXPR_NOT, $2.parse, pnull() ); } | `(` expr `)` { $$.parse = $2.parse; } ; /* * cases - action elements inside a 'switch' * case - a single action element inside a 'switch' * right-recursive rule so cases can be examined in order. */ cases : /* empty */ { $$.parse = P0; } | case cases { $$.parse = pnode( $1.parse, $2.parse ); } ; case : `case` ARG `:` block { $$.parse = psnode( $2.string, $4.parse ); } ; /* * params - optional parameter names to rule definition * right-recursive rule so that params can be added in order. */ params : /* empty */ { $$.parse = P0; } | ARG `:` params { $$.parse = psnode( $1.string, $3.parse ); } | ARG { $$.parse = psnode( $1.string, P0 ); } ; /* * lol - list of lists * right-recursive rule so that lists can be added in order. */ lol : list { $$.parse = pnode( P0, $1.parse ); } | list `:` lol { $$.parse = pnode( $3.parse, $1.parse ); } ; /* * list - zero or more args in a LIST * listp - list (in puncutation only mode) * arg - one ARG or function call */ list : listp { $$.parse = $1.parse; yymode( SCAN_NORMAL ); } ; listp : /* empty */ { $$.parse = pnull(); yymode( SCAN_PUNCT ); } | listp arg { $$.parse = pappend( $1.parse, $2.parse ); } ; arg : ARG { $$.parse = plist( $1.string ); } | `[` { yymode( SCAN_NORMAL ); } func `]` { $$.parse = $3.parse; } ; /* * func - a function call (inside []) * This needs to be split cleanly out of 'rule' */ func : arg lol { $$.parse = prule( $1.parse, $2.parse ); } | `on` arg arg lol { $$.parse = pon( $2.parse, prule( $3.parse, $4.parse ) ); } | `on` arg `return` list { $$.parse = pon( $2.parse, $4.parse ); } ; /* * eflags - zero or more modifiers to 'executes' * eflag - a single modifier to 'executes' */ eflags : /* empty */ { $$.number = 0; } | eflags eflag { $$.number = $1.number | $2.number; } ; eflag : `updated` { $$.number = RULE_UPDATED; } | `together` { $$.number = RULE_TOGETHER; } | `ignore` { $$.number = RULE_IGNORE; } | `quietly` { $$.number = RULE_QUIETLY; } | `piecemeal` { $$.number = RULE_PIECEMEAL; } | `existing` { $$.number = RULE_EXISTING; } | `maxline` ARG { $$.number = atoi( $2.string ) * RULE_MAXLINE; } ; /* * bindlist - list of variable to bind for an action */ bindlist : /* empty */ { $$.parse = pnull(); } | `bind` list { $$.parse = $2.parse; } ;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4381 | Lawrence You | Branch files for jam at change #3108 to prepare for a fix. | ||
//guest/perforce_software/jam/src/jamgram.yy | |||||
#13 | 3065 | Perforce staff |
Support for 'actions ... maxline value', to set a command specific maxline (rather than the OS-specific maximum). Undocumented. |
||
#12 | 2559 | rmg |
Fix 'var on target ?= value' so that var is only set if it did not have a target-specific value. Previously, it would just overwrite the var's value. Bug fix documented in RELNOTES. === computer:1666: Change 39566 by seiwald@play-seiwald on 2002/12/27 14:44:01 |
||
#11 | 2493 | rmg |
Rewrite the past: update all jam's source with comments to reflect changes since about 2.3, very early 2001. Whitespace only change. === computer:1666: Change 37660 by seiwald@play-seiwald on 2002/11/06 22:41:35 Note: I regenerated jamgram.c on my linux 7.3 system prior to the submit, since patch was so unhappy trying to lay down the changes from Christopher's change. Presumably this is just due to different yacc/bison/whatever particulars on the system where Christopher made the changes originally. - rmg |
||
#10 | 2490 | rmg |
Jam langauge work: make 'return' actually return from the rule, rather than just setting the return value. Introduce new break/continue statements for managing loops. User visible change to be documented in Jam.html. === computer:1666: Change 37200 by seiwald@play-seiwald on 2002/10/22 15:41:28 Gross rework of Jam.html documentation, including: - the description of parameters for rules - description of -g flag - a new description of targets - more about rules and their return values - better separation of rules and updating actions - putting borders around the tables (Undocumented) change to documentation. === computer:1666: Change 37551 by seiwald@waffle-cyg-seiwald on 2002/11/03 23:17:12 Document jam's new and working break/continue/return statements. === computer:1666: Change 37574 by seiwald@play-seiwald on 2002/11/04 13:13:01 |
||
#9 | 2482 | rmg |
Jam.html partial rewrite and the support for named parameters to rules. === computer:1666: Change 34516 by seiwald@play-seiwald on 2002/06/21 23:59:12 |
||
#8 | 1535 | Perforce staff | Define YYMAXDEPTH to 10000 to handle right-recursive rules. | ||
#7 | 1497 | Perforce staff |
Support for invoking rules via variable expansion, i.e. "$(rule) targets : sources ;". Not yet documented. Documented in Jam.html (rmg change 1536) |
||
#6 | 1492 | Perforce staff |
Replace action modifiers EXEC_* from compile.h with RULE_* flags from rules.h. They've always been the same quantity defined in two places. Note that RULE_NEWSRCS is now RULE_UPDATED, to be consistent with 'actions updated'. No functional change. |
||
#5 | 1489 | Perforce staff |
Revert syntax of "expr : expr `in` expr" to jam 2.3's "expr : arg `in` list", because: a) It broke the precedence of `in` so that it was looser than !, parsing "! xxxx in yyy" as '( ! xxx ) in yyy". b) It didn't allow providing an in line list as "$(f) in a b c". Change to unreleased behavior. |
||
#4 | 1319 | rmg |
Jam 2.3 + Perforce's internal changes. This change is a drop of the Perforce internal Jam changes since the 2.3 public release. The individual changes represented herein are preserved in the //guest/richard_geiger/intjam/ branch. The intent of this drop is to provide a base, from which other contributors' Jam branches may be integrated into. It is not intended to become a packaged release in this state. We will be integrating changes from other users prior to creating the next packaged release. Please refer to the src/RELNOTES file for an overview of the changes present in this integration. - Richard Geiger Open Source Engineer at Perforce |
||
#3 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#2 | 3 | Perforce maintenance | Jam/MR 2.2.1 (fix for NT handle leak) | ||
#1 | 2 | laura | Add Jam/MR 2.2 source |