Sponsored Content
Full Discussion: Expression syntax
Top Forums Shell Programming and Scripting Expression syntax Post 302298560 by morava on Wednesday 18th of March 2009 01:56:20 AM
Old 03-18-2009
Expression syntax

Hello, I am getting Expression syntax message and I cannot figure out what's wrong. This program will print all the odd numbers between 0 and the one the user enters, in cshell. I think my logic is either good or almost there, but i dont see the errors. I think it could be the spaces between characters, maybe? Thanks !
Monika

This is what I have: odds:

#!/bin/csh
# Print out all the odd numbers between 1 and a number user specifies
# If user enters a negative number, print out an error message
echo "Enter your number: "
set number = $<
set x=1
while ($x <=$number)
echo $x
@x =$x + 2
end
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

One more expression syntax error

HI again, still working on the assignment, which is really hard given we just started unix 4 weeks ago. This script should change the permission for the user depending if its x, w or r, to the opposite. When i try to run it, I am getting expression error. Can you spot where the problem is? I really... (3 Replies)
Discussion started by: morava
3 Replies

2. Shell Programming and Scripting

syntax error for if statment test expression

Hi what's the correct way of writing if 1)if "$time_diff" -gt 5 then echo "killing hung process \n" fi 2)if test $time_diff -gt 5 then echo "killing hung process \n" fi where -time_diff=$(($Sam - $current_min)) and current_min=`date +%M` infact both are giving Syntax... (1 Reply)
Discussion started by: Anteus
1 Replies

3. UNIX for Dummies Questions & Answers

Syntax Help | unix | grep | regular expression | repetition

Hello, This is my first post so, Hello World! Anyways, I'm learning how to use unix and its quickly become apparent that a strong foundation in regular expressions will make things easier. I'm not sure if my syntax is messing things up or my logic is messing things up. ps -e | grep... (4 Replies)
Discussion started by: MykC
4 Replies

4. UNIX for Dummies Questions & Answers

Help | Unix | grep | regular expression | backreference | Syntax/Logic

Hello, I'm working on learning regular expressions and what I can do with them. I'm using unix to and its programs to experiment and learn what my limitations are with them. I'm working on duplicating the regular expression: ^(.*)(\r?\n\1)+$ This is supposed to delete duplicate lines... (2 Replies)
Discussion started by: MykC
2 Replies

5. Shell Programming and Scripting

if expression syntax error

#! /bin/csh set umr=UMR foreach i ( `ls`) set file_nm=$i set bh_nm=`echo $file_nm | cut -d"_" -f2` if($bh_nm !=$umr) then { set bh_ext=`echo $file_nm | cut -d"_" -f4` set bh_num_nm="$bh_nm $bh_ext a .txt" mv $file_nm $bh_num_nm } ... (1 Reply)
Discussion started by: jdsignature88
1 Replies

6. UNIX for Dummies Questions & Answers

If Then ElseIf Script - Confusion Around Expression's Syntax

Hello, I am relatively new to UNIX scripting and am learning a lot. I have already tried several searches on this website and have tried various syntax options suggested to no avail. I am obviously not writing the script correctly. I really do appreciate any and all the help. Below is an... (8 Replies)
Discussion started by: dqrgk0
8 Replies

7. Shell Programming and Scripting

if: expression syntax error in gawk

I'm pretty new to shell scripting, but I am catching on quick. I did see one of the stickied threads about the csh, and I think this is relevant, but I don't understand enough to make a decision based on it. So as you'll see below, I use the |csh pipe, and if that is not correct, I'm certainly... (2 Replies)
Discussion started by: macman104
2 Replies

8. Shell Programming and Scripting

If expression syntax

Hello there! I am having some difficulties in the syntax of a script. I am a newbie :) What i want is a script that copies 1 or more files to a destination folder with a question if file allready exists if ($#argv > 2) then if (-d $argv($#argv)) then foreach x ($*) cp -i $x to... (4 Replies)
Discussion started by: ennui92
4 Replies

9. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies

10. Shell Programming and Scripting

TCL: syntax error in expression with "*"

I'm using tcl scripts in ns2 ( network simulator) through cygwin. It works fine , however, I downloaded an example when i run it , I got the following syntax error: syntax error in expression with " *2" : unexpected operator * while executing : "expr $bw *2" invoked from within: "$ns... (1 Reply)
Discussion started by: ENG_MOHD
1 Replies
pt::pgen(n)							   Parser Tools 						       pt::pgen(n)

__________________________________________________________________________________________________________________________________________________

NAME
pt::pgen - Parser Generator SYNOPSIS
package require Tcl 8.5 package require pt::pgen ?1? ::pt::pgen inputformat text resultformat ?options...? _________________________________________________________________ DESCRIPTION
Are you lost ? Do you have trouble understanding this document ? In that case please read the overview provided by the Introduction to Parser Tools. This document is the entrypoint to the whole system the current package is a part of. This package provides a command implementing a parser generator taking parsing expression grammars as input. It is the implementation of method generate of pt, the Parser Tools Application. As such the intended audience of this document are people wishing to modify and/or extend this part of pt's functionality. Users of pt on the other hand are hereby refered to the applications' manpage, i.e. Parser Tools Application. It resides in the User Package Layer of Parser Tools. IMAGE: arch_user_pkg API
::pt::pgen inputformat text resultformat ?options...? This command takes the parsing expression grammar in text (in the format specified by inputformat), and returns the same grammar in the format resultformat as the result of the command. The two known input formats are peg and json. Introductions to them, including their formal specifications, can be found in the PEG Language Tutorial and The JSON Grammar Exchange Format. The packages used to parse these formats are peg pt::peg::from::peg json pt::peg::from::json On the output side the known formats, and the packages used to generate them are c pt::peg::to::cparam container pt::peg::to::container critcl pt::peg::to::cparam + pt::cparam::configuration::critcl json pt::peg::to::json oo pt::peg::to::tclparam + pt::tclparam::configuration::tcloo peg pt::peg::to::peg snit pt::peg::to::tclparam + pt::tclparam::configuration::snit The options supported by each of these formats are documented with their respective packages. EXAMPLE
In this section we are working a complete example, starting with a PEG grammar and ending with running the parser generated from it over some input, following the outline shown in the figure below: IMAGE: flow Our grammar, assumed to the stored in the file "calculator.peg" is PEG calculator (Expression) Digit <- '0'/'1'/'2'/'3'/'4'/'5'/'6'/'7'/'8'/'9' ; Sign <- '-' / '+' ; Number <- Sign? Digit+ ; Expression <- '(' Expression ')' / (Factor (MulOp Factor)*) ; MulOp <- '*' / '/' ; Factor <- Term (AddOp Term)* ; AddOp <- '+'/'-' ; Term <- Number ; END; From this we create a snit-based parser using the script "gen" package require Tcl 8.5 package require fileutil package require pt::pgen lassign $argv name set grammar [fileutil::cat $name.peg] set plass [pt::pgen peg $gr snit -class $name -file $name.peg -name $name] fileutil::writeFile $name.tcl $pclass exit 0 calling it like tclsh8.5 gen calculator which leaves us with the parser package and class written to the file "calculator.tcl". Assuming that this package is then properly installed in a place where Tcl can find it we can now use this class via a script like package require calculator lassign $argv input set channel [open $input r] set parser [calculator] set ast [$parser parse $channel] $parser destroy close $channel ... now process the returned abstract syntax tree ... where the abstract syntax tree stored in the variable will look like set ast {Expression 0 4 {Factor 0 4 {Term 0 2 {Number 0 2 {Digit 0 0} {Digit 1 1} {Digit 2 2} } } {AddOp 3 3} {Term 4 4 {Number 4 4 {Digit 4 4} } } } } assuming that the input file and channel contained the text 120+5 A more graphical representation of the tree would be IMAGE: expr_ast Regardless, at this point it is the user's responsibility to work with the tree to reach whatever goal she desires. I.e. analyze it, trans- form it, etc. The package pt::ast should be of help here, providing commands to walk such ASTs structures in various ways. One important thing to note is that the parsers used here return a data structure representing the structure of the input per the grammar underlying the parser. There are no callbacks during the parsing process, i.e. no parsing actions, as most other parsers will have. Going back to the last snippet of code, the execution of the parser for some input, note how the parser instance follows the specified Parser API. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category pt of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
EBNF, LL(k), PEG, TDPL, context-free languages, expression, grammar, matching, parser, parsing expression, parsing expression grammar, push down automaton, recursive descent, state, top-down parsing languages, transducer CATEGORY
Parsing and Grammars COPYRIGHT
Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net> pt 1 pt::pgen(n)
All times are GMT -4. The time now is 06:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy