명령행 계산기 만들때요

geneven의 이미지

예전 군입대 전에 학교 숙제로 명령행 계산기를 만드는 숙제를 학교에서 내준적이 있었는데 게을러서 그런것도 있고 워낙 빡센수업이 같이 있어서 결국에는 해결 못했던 기억이 나네요.

지금와서 다시 생각해봐도 어떻게 해야할지 잘 모르겠는데 자료구조를 어떤걸 써서 해결해야 쉽게 해결할수 있죠?

File attachments: 
첨부파일 크기
파일 EXPARSER.C9.33 KB
파일 ECALC.C815바이트
파일 TREE1.C4.23 KB
파일 EXPARSER.H650바이트
taeyeung의 이미지

DC라는 명령행 계산기 소스를 분석해 보시지요

http://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html

cppig1995의 이미지

이런 문제 같은 경우엔 후위표기법을 사용하시면서 스택을 이용해 풀어야 합니다.

2 + 3 * 5 라는 수식이 있다면 수식 나무 (Parse Tree) 를 통해
후위표기법 2 3 5 * + 으로 변환하신 뒤 스택으로 후위 표기법을
푸는 알고리즘을 이용하시면 되겠습니다.

C로 배우는 알고리즘 (1) - 이재규, 세화 3장 11절 "나무 구조의 응용 : 수식 나무(Parse Tree)" (pp. 250-261)
C로 배우는 알고리즘 (2) - 이재규, 세화 10장 2절 "수식 분석과 계산(Expression Parsing & Evaluation)" (pp. 1211-1241)

참고하시기 바라며, 소스 코드를 첨부하겠습니다.

댓글 첨부 파일: 
첨부파일 크기
파일 0바이트
파일 0바이트
파일 0바이트

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

cppig1995의 이미지

위 3개의 첨부파일 외에도 2편 10장 2절의 EXPARSER.H 가
필요하게 됩니다. 파일 첨부하겠습니다.

(게시물당 파일 첨부 최대 3개 제한 때문에)

댓글 첨부 파일: 
첨부파일 크기
파일 0바이트

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

오호라의 이미지

너무 앞서가는 것 같지만...

COMPILERS:PRINCIPLES,TECHNIQUES,AND TOOLS (한국어판)

앞부분(스캐너, 형태소분석기) 내용이 postfix calculator (stack) 입니다.

명령행 계산기도 일종의 인터프린터...

나중에 shell을 만들어볼때도 많은 도움이 될겁니다.

Hello World.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.