User Tools

Site Tools


scan_statement

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
scan_statement [2020/09/25 11:04]
revusky [The SCAN construct also allows the newer LOOKBEHIND construct.]
scan_statement [2021/02/08 18:16] (current)
revusky
Line 1: Line 1:
 ===== The new SCAN Statement ===== ===== The new SCAN Statement =====
  
-JavaCC 21 introduces a new ''SCAN'' statement that is designed to supersede the legacy ''LOOKAHEAD''. It is a key part of the [[new_syntax_summary|newer streamlined syntax]].+JavaCC 21 introduces a new ''SCAN'' statement that is designed to supersede the legacy ''LOOKAHEAD''. It is a key part of the [[new_syntax_summary|newer streamlined syntax]]. Like ''LOOKAHEAD'', ''SCAN'' exists to specify conditions at [[choice points]] that override the default resolution mechanism of scanning ahead exactly one token. The new ''SCAN'' construct provides a superset of the functionality of ''LOOKAHEAD'' and tends to more succinct and readable. (Sometimes dramatically so.)
  
 Note, however, that the older ''LOOKAHEAD'' syntax still works and will work for the foreseeable feature.  Note, however, that the older ''LOOKAHEAD'' syntax still works and will work for the foreseeable feature. 
- 
 Here is a rundown of the differences between ''SCAN'' and the older ''LOOKAHEAD''. Here is a rundown of the differences between ''SCAN'' and the older ''LOOKAHEAD''.
  
Line 97: Line 96:
  
  
-==== The SCAN construct also allows the newer LOOKBEHIND construct. ====+==== The SCAN construct also you to use contextual predicates. ====
  
-The //lookbehind// construct allows you to express conditions based on scanning backwards in the lookahead/call stack +The [[contextual_predicates]] construct allows you to express conditions based on scanning backwards in the lookahead/call stack. This can only be used in conjunction with the newer ''SCAN'' statement, not with the legacy ''LOOKAHEAD'' construct. 
  
-You can find more information [[lookbehind|here]].+You can find more information [[contextual_predicates|here]].
  
 ==== Addendum: the SCAN-less SCAN? ==== ==== Addendum: the SCAN-less SCAN? ====
Line 160: Line 159:
 </code> </code>
  
-In this case, because I think it is so common, we decided to allow this. And, in fact, you can see that this is already used in internal development, for example [[https://github.com/javacc21/javacc21/blob/master/src/main/grammars/JavaCC.javacc#L1028|here]].+In this case, because I think it is so common, we decided to allow this. And, in fact, you can see that this is already used in internal development, for example [[https://github.com/javacc21/javacc21/blob/master/src/main/grammars/JavaCC.javacc#L1950|here]]
 + 
 + 
 +==== Recap ==== 
 + 
 +The new ''SCAN'' instruction in JavaCC 21 totally supersedes the legacy tool's ''LOOKAHEAD''. It allows you to specify in the following order: 
 +  * //numerical// lookahead, i.e. the maximum number of tokens to scan ahead 
 +  * [[semantic lookahead]], i.e. arbitrary java code enclosed in {..} 
 +  * a [[contextual_predicates]] predicate 
 +  * [[syntactic lookahead]] 
 + 
 +Caveats:  
 +  * The ''SCAN'' construct can specify all (or none) of the above, except that //numerical// lookahead and [[syntactic lookahead]] are mutually exclusive.  
 +  * If no numerical or syntactic lookahead is specified, the generated code will scan ahead an //unlimited// number of tokens. This differs from the legacy tool. 
 + 
 +Note that an empty SCAN statement can be simply written alternatively with a lone arrow, i.e. ''=>''.
  
-===== The newer SCAN construct allows you to use the newer "lookbehind" construct  
  
-This is documented separately. 
  
scan_statement.1601031848.txt.gz · Last modified: 2020/09/25 11:04 by revusky